package com.jinmdz.fmis.api.api.controller;

import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.api.model.photoarchival.PhotoArchivalAllData;
import com.jinmdz.fmis.api.api.model.photoarchival.PhotoArchivalData;
import com.jinmdz.fmis.api.api.model.photoarchival.PhotoArchivalItem;
import com.jinmdz.fmis.api.api.model.photoarchival.PhotoArchivalTypeData;
import com.jinmdz.fmis.api.api.service.PhotoArchivalService;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.model.document.PhotoDocumentFileItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;


/**
 * 拍照备案相关接口
 *
 * @author GuanKui
 * @date 2020/2/19 10:59
 */
@Api(description = "拍照备案相关接口")
@RestController()
@RequestMapping("/api/photo-archival")
public class PhotoArchivalController extends BaseController {

    @Resource
    private PhotoArchivalService photoArchivalService;

    /**
     * 根据funeral_dead表中businessCode加载拍照备案页面所有信息
     *
     * @param data 加载条件
     * @return
     * @author GuanKui
     * @date 2020/2/20 13:38
     */
    @ApiOperation(value = "根据funeral_dead表中businessCode加载拍照备案页面所有信息",
            notes = "根据businessCode加载信息，包括：逝者信息、逝者家属信息、承办人信息、照片类型字典信息和备案照片记录信息")
    @PostMapping("/load-photo-archival-all")
    public BaseResult<PhotoArchivalItem> loadPhotoArchivalAll(@RequestBody PhotoArchivalAllData data) {
        return resultHandler(data, userItem -> photoArchivalService.loadPhotoArchivalAll(data));
    }


    /**
     * 按拍照备案文档类型
     *
     * @param data 文档类型
     * @return
     * @author GuanKui
     * @date 2020/2/20 13:38
     */
    @ApiOperation(value = "按拍照备案文档类型，加载图片信息",
            notes = "按拍照备案文档类型【字典：document_type】，加载图片信息")
    @PostMapping("/load-photo-archival-with-document-type")
    public BaseResult<ArrayList<PhotoDocumentFileItem>> loadPhotoArchivalByDocumentType(@RequestBody PhotoArchivalTypeData data) {
        return resultHandler(data, userItem -> photoArchivalService.loadPhotoArchivalByDocumentType(data));
    }

    /**
     * 保存拍照备案信息
     *
     * @param data 图片类型信息
     * @return
     * @author GuanKui
     * @date 2020/2/20 13:38
     */
    @ApiOperation(value = "保存拍照备案信息",
            notes = "保存拍照备案记录，数据保存到数据表【document_file】，上次拍照照片")
    @PostMapping("/save-photo-archival")
    public BaseResult<PhotoArchivalItem> savePhotoArchival(@RequestBody PhotoArchivalData data) {
        return resultHandler(data, userItem -> photoArchivalService.savePhotoArchival(userItem, data.getData(), data.getCertificatesImageFile(), data.getPeopleImageFile()));
    }

    /**
     * 删除拍照备案拍摄的图片
     *
     * @param data 主键和版本号
     * @return
     * @author GaoXiangLiang
     * @date 2020-05-11 14:38
     */
    @ApiOperation(value = "从cremation表中删除指定id的火化任务信息", notes = "从cremation表中删除指定id的火化任务信息")
    @PostMapping("/delete-photo-archival-with-id")
    public BaseResult deletePhotoArchivalWithId(@RequestBody IdVersionData data) {
        return resultHandler(data, userItem -> photoArchivalService.deletePhotoArchivalWithId(userItem, data));
    }

    /**
     * 保存人证核验数据
     *
     * @param data 图片类型信息
     * @return
     * @author GuanKui
     * @date 2020/2/20 13:38
     */
    @ApiOperation(value = "保存人证核验数据",
            notes = "保存人证核验记录，数据保存到数据表【document_file】两张图片")
    @PostMapping("/save-one-card-to-check")
    public BaseResult<PhotoArchivalItem> saveOneCardToCheck(@RequestBody PhotoArchivalData data) {
        return resultHandler(data, userItem -> photoArchivalService.saveOneCardToCheck(userItem, data.getData(), data.getCertificatesImageFile(), data.getPeopleImageFile()));
    }

}
